package com.api.shopapi.service.impl;


import com.api.shopapi.entity.Role;
import com.api.shopapi.entity.dto.RoleDTO;
import com.api.shopapi.mapper.RoleMapper;
import com.api.shopapi.service.RoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("RoleServiceImplOne")
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public int insert(Role role){
        return roleMapper.insert(role);
    }

    @Override
    public int deleteByRoleCode(String roleCode){
        return roleMapper.deleteByRoleCode(roleCode);
    }

    @Override
    public int updateByRoleCode(Role role){
        return roleMapper.updateByRoleCode(role);
    }

    @Override
    public Role getByRoleCode(String roleCode){
        return roleMapper.getByRoleCode(roleCode);
    }

    @Override
    public Role getByName(String name){
        return roleMapper.getByName(name);
    }


    @Override
    public List<Role> getList() {
        return roleMapper.getList();
    }




    @Override
    public PageInfo<Role> getPageInfo(int pageIndex, int pageSize){
        PageHelper.startPage(pageIndex, pageSize);
        List<Role> listRole = roleMapper.getList();
        PageInfo<Role> pageInfo = new PageInfo<Role>(listRole);
        return pageInfo;
    }

    @Override
    public PageInfo<RoleDTO> getPageInfoRoleDTO(int pageIndex, int pageSize){
        PageHelper.startPage(pageIndex, pageSize);
        List<RoleDTO> listRoleDTO = roleMapper.getListDTO();
        PageInfo<RoleDTO> pageInfo = new PageInfo<RoleDTO>(listRoleDTO);
        return pageInfo;
    }


}
